﻿using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;

namespace ExpressionVisualizer
{
    class ExpressionTreeVisualizer : DialogDebuggerVisualizer
    {
        public ExpressionTreeVisualizer() : base(FormatterPolicy.NewtonsoftJson)
        {

        }
        public ExpressionTreeVisualizer(FormatterPolicy preferredFormatterPolicy) : base(preferredFormatterPolicy)
        {
        }

        // Methods
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            IVisualizerObjectProvider3 objectProvider3 = objectProvider as IVisualizerObjectProvider3;
            ExpressionTreeContainer container = objectProvider3?.GetObject<ExpressionTreeContainer>();

            if(container != null)
            {
                TreeView view = new TreeView();
                view.Nodes.Add(container.TreeNode);
                using(TreeWindow form = new TreeWindow())
                {
                    form.ShowInTaskbar = false;
                    form.Set(view, container.Expression);

                    windowService.ShowDialog(form);
                }
            }
        }
    }
}